using System.Linq;
using Magiq.Tests.TestModel;
using NUnit.Framework;

namespace Magiq.Tests {
    public abstract class BaseMagiqProviderTest<T, TI>
        where T : class, ITestClass1<T>, new() where TI : ITestClass1Inheritor<T>, T, new() {
        protected IMagiqTestConfigurator Configurator { get; private set; }

        protected IQueryable<T> TestClass1s { get; private set; }
        protected IQueryable<TestClass2> TestClass2s { get; private set; }
        protected IQueryable<TestClass3> TestClass3s { get; private set; }
        protected abstract IMagiqTestConfigurator GetConfigurator();

        private void InitModel() {
            var domain = new TestDomain<T, TI>();

            Configurator.Persist(domain.Class2s);
            Configurator.Persist(domain.Class1s);
            Configurator.Reload();
            TestClass1s = Configurator.GetQueryable<T>();
            TestClass2s = Configurator.GetQueryable<TestClass2>();
            TestClass3s = Configurator.GetQueryable<TestClass3>();
        }

        [TestFixtureSetUp]
        public void FixtureSetUp() {
            Configurator = GetConfigurator();
        }

        [SetUp]
        public void SetUp() {
            Configurator.SetUp();
            InitModel();
            Initialize();
        }

        [TearDown]
        public void TearDown() {
            Configurator.TearDown();
        }

        protected virtual void Initialize() {}
        }
}